<?php $this->load->view('header'); ?>
<?php $this->load->view('cuerpo'); ?>
<link rel="stylesheet" href="<?php echo base_url(); ?>css/rating.css" />
<script type="text/javascript" src="<?php echo base_url(); ?>js/rating.js"></script>
<style type="text/css">
    .btn-primary {
        background-color: #d9534f;
        border-color: #d43f3a;
        color: #fff;
    }
    .btn {
        -moz-user-select: none;
        background-image: none;
        border: 1px solid transparent;
        border-radius: 4px;
        cursor: pointer;
        display: inline-block;
        font-size: 12px;
        font-weight: normal;
        line-height: 1;
        margin-bottom: 0;
        padding: 6px 12px;
        text-align: center;
        vertical-align: middle;
        white-space: nowrap;
    }    
</style>
<script type="text/javascript">
    $(function() {
        var numProveedores = $("#numProveedores").val();
        if (numProveedores > 0) {
            for(i=0;i<numProveedores;i++) {
                $('#star-rating'+i).rating();
            }
        }
        $('#star-rating-calificar').rating();
        $('#thumbnails a').lightBox();
        <?php
            if ($idSolicitud > 0) {
                if (isset($objSolicitud[0]->entrega_taller)) {
                    if ($objSolicitud[0]->entrega_taller == 1) {
        ?>
                        $("#otroLugar").removeAttr("checked");
                        $("#dirOtroLugar").attr("disabled", "disabled");
                        $("#dirOtroLugar").val("");
        <?php
                        if (isset($objSolicitud[0]->id_taller) && $objSolicitud[0]->id_taller > 0) {
        ?>
                            var idTaller = <?= $objSolicitud[0]->id_taller ?>;
                            if (idTaller !== "") {
                                $.ajax({
                                    url: "../solicitud/mostrarDirTaller",
                                    type: "post",
                                    data: "idTaller="+idTaller,
                                    success: function(data) {
                                        $("#dirTaller").val(data);
                                    }
                                });
                            } else {
                                $("#dirTaller").val("");
                            }
        <?php
                        }
                    } else {
        ?>
                        $("#idTaller").attr("disabled", "disabled");
                        $("#idTaller").val("");
                        $("#dirTaller").attr("disabled", "disabled");
                        $("#dirTaller").val("");
        <?php
                        if (isset($objSolicitud[0]->otro_taller) && $objSolicitud[0]->otro_taller != "") {
        ?>
                            $("#otroLugar").attr("checked", "checked");
                            $("#dirOtroLugar").val("<?= $objSolicitud[0]->otro_taller ?>");
        <?php

                        }
                    }
                }
            }
        ?>
    });
</script>
<script type="text/javascript">
    function soloNumeros(e) {
        var key = window.Event ? e.which : e.keyCode;
        return ((key >= 48 && key <= 57) || (key===8));
    }    
</script>
<div class="formulario" style="width: 980px; margin-left: -20px">
<form id="solicitud" name="solicitud" method="post" action="<?php echo base_url(); ?>index.php/solicitud/valorar" enctype="multipart/form-data">
    <fieldset>
        <legend>DATOS DE SOLICITUD</legend>
        <table>
            <tr>
                <td><label>N° de Solicitud</label></td>
                <td style="width: 180px;">
                    <input type="text" placeholder="N° de Solicitud" id="numCaso" name="numCaso" value="<?= $codigo ?>" maxlength="10" onkeypress="return soloNumeros(event)" <?= $indLectura ?>/>
                </td>
                <td><input type="button" id="btnBuscar" name="btnBuscar" value="O" <?= $indLectura ?>/>
                    <script type="text/javascript">
                        $("#btnBuscar").click(function() {
                            var numCaso = $("#numCaso").val();
                            if (numCaso === "") {
                                alert('Ingresar el número de solicitud');
                                return false;
                            } else {
                                $("#solicitud").submit();
                            }
                        });
                    </script>                
                </td>
                <td colspan="3"></td>
                <td colspan="2">
                    <label style="color: #000000; font-weight: bold; padding-right: 20px;"></label>
                    <label style="color: #0063DC; font-weight: bold; padding-right: 20px;">La solicitud debe de cotizarse en</label>
                    <select id="moneda" name="moneda" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0 ) {
                                foreach($lstMoneda as $data) {
                                    $selected = '';
                                    if ($data->id_tabla_maestra == $objSolicitud[0]->id_moneda) {
                                        $selected = ' selected="selected"';
                                    }
                        ?>
                        <option value="<?= $data->id_tabla_maestra ?>" <?= $selected ?>><?= $data->valor_1 ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="6"></td>
                <td colspan="2">
                    <label style="color: #0063DC; font-weight: bold; padding-left: 110px; padding-right: 10px;">y los precios deben</label>
                    <?php if ($idSolicitud > 0) { ?>
                    <input type="radio" id="igv" name="igv" value="0" required <?= $lectura ?> <?php if($objSolicitud[0]->igv == 0) { echo 'checked="checked"'; } ?>/>No Incluye IGV
                    <input type="radio" id="igv" name="igv" value="1" required <?= $lectura ?> <?php if($objSolicitud[0]->igv == 1) { echo 'checked="checked"'; } ?>/>Incluye IGV
                    <?php } else { ?>
                    <input type="radio" id="igv" name="igv" value="0" required <?= $lectura ?>/>No Incluye IGV
                    <input type="radio" id="igv" name="igv" value="1" required <?= $lectura ?>/>Incluye IGV
                    <?php } ?>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>CONDICIONES DE ENTREGA</legend>
        <table>
            <tr>
                <td><label>Entrega en Taller</label></td>
                <td>
                    <select id="entregaTaller" name="entregaTaller" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach ($lstEntrega as $key => $value) {
                                    $selected = '';
                                    if (isset($objSolicitud[0]->entrega_taller)) {
                                        if ($key == $objSolicitud[0]->entrega_taller) {
                                            $selected = ' selected="selected"';
                                        }
                                    }
                        ?>
                        <option value="<?= $key ?>" <?= $selected ?>><?= $value ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>
                </td>
                <td><label>Nombre de Taller:</label></td>
                <td>
                    <select id="idTaller" name="idTaller" disabled="disabled">
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach ($lstTaller as $data) {
                                    $selected = '';
                                    if (isset($objSolicitud[0]->id_taller)) {
                                        if ($data->id_tabla_maestra == $objSolicitud[0]->id_taller) {
                                            $selected = ' selected="selected"';
                                        }
                                    }
                        ?>
                        <option value="<?= $data->id_tabla_maestra ?>" <?= $selected ?>><?= $data->valor_1 ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>                    
                </td>
                <td><label>Dirección de Taller:</label></td>
                <td colspan="3">
                    <input type="text" placeholder="Dirección del Taller" id="dirTaller" name="dirTaller" disabled="disabled" readonly="readonly" maxlength="60" style="width: 300px;" value="" <?= $lectura ?>/>
                </td>
            </tr>
            <tr>
                <td colspan="4"></td>
                <td style="padding-left: 95px; text-align: right;">
                    <input type="checkbox" id="otroLugar" name="otroLugar" value="1" <?= $lectura ?>/>
                </td>
                <td colspan="3">
                    <input type="text" placeholder="Entrega en otro lugar" id="dirOtroLugar" name="dirOtroLugar" disabled="disabled" maxlength="80" style="width: 300px;" onkeyup="javascript:this.value=this.value.toUpperCase()"/>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>DATOS DEL AUTOMOVIL</legend>
        <table>
            <tr>
                <td><label>Marca:</label></td>
                <td>
                    <select id="marca" name="marca" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach($lstMarca as $data) {
                                    $selected = '';
                                    if ($data->id_marca == $objMarca[0]->id_marca) {
                                        $selected = ' selected="selected"';
                                    }
                        ?>
                        <option value="<?= $data->id_marca ?>" <?= $selected ?>><?= $data->nombre ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>
                </td>
                <td><label>Tipo de Carroceria:</label></td>
                <td>
                    <select id="tipoCarroceria" name="tipoCarroceria" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach($lstTipoCarroceria as $data) {
                                    $selected = '';
                                    if ($data->id_tabla_maestra == $objSolicitud[0]->id_tipo_carroceria) {
                                        $selected = ' selected="selected"';
                                    }                                
                        ?>
                        <option value="<?= $data->id_tabla_maestra ?>" <?= $selected ?>><?= $data->valor_1 ?></option>
                        <?php
                                }
                            }                                
                        ?>
                    </select>
                </td>
                <td><label>Modelo:</label></td>
                <td>
                    <select id="modelo" name="modelo" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach($lstModelo as $data) {
                                    $selected = '';
                                    if ($data->id_modelo == $objSolicitud[0]->id_modelo) {
                                        $selected = ' selected="selected"';
                                    }
                        ?>
                        <option value="<?= $data->id_modelo ?>" <?= $selected ?>><?= $data->nombre ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td><label>Año:</label></td>
                <td>
                    <select id="anho" name="anho" required <?= $lectura ?>>
                        <option value=""><?= $valorInicial ?></option>
                        <?php
                            if ($idSolicitud > 0) {
                                foreach($lstAnho as $key=>$value) {
                                    $selected = '';
                                    if ($key == $objSolicitud[0]->ano) {
                                        $selected = ' selected="selected"';
                                    }
                        ?>
                        <option value="<?= $key ?>" <?= $selected ?>><?= $value ?></option>
                        <?php
                                }
                            }
                        ?>
                    </select>
                </td>
                <td><label>Placa:</label></td>
                <td><input type="text" placeholder="Placa" id="placa" name="placa" maxlength="6" onkeyup="javascript:this.value=this.value.toUpperCase()" value="<?php if(isset($objSolicitud[0]->placa)) { echo $objSolicitud[0]->placa; } ?>" <?= $lectura ?>/></td>
                <td><label>VIN:</label></td>
                <td><input type="text" placeholder="VIN" id="vin" name="vin" maxlength="17" required onkeyup="javascript:this.value=this.value.toUpperCase()" value="<?php if(isset($objSolicitud[0]->vin)) { echo $objSolicitud[0]->vin; } ?>" <?= $lectura ?>/></td>
            </tr>
            <tr>
                <td><label>Versión:</label></td>
                <td><input type="text" placeholder="Versión" id="version" name="version" maxlength="30" onkeyup="javascript:this.value=this.value.toUpperCase()" value="<?php if(isset($objSolicitud[0]->version)) { echo $objSolicitud[0]->version; } ?>" <?= $lectura ?>/></td>
                <td></td>
                <td>
                    <?php
                        if ($idSolicitud > 0) {
                            if (isset($objSolicitud[0]->foto_vehiculo) && $objSolicitud[0]->foto_vehiculo != '') {
                    ?>
                    <span id="thumbnails">
                        <ul>
                            <li>
                                <a href="<?= "../.".$objSolicitud[0]->foto_vehiculo ?>" title="Foto Vehículo" class="btn btn-primary" style="color: #ffffff; text-decoration: none;">Ver Foto</a>
                            </li>
                        </ul>
                    </span>
                    <?php   }
                        }
                    ?>
                </td>
            </tr>
	</table>
    </fieldset>
    <?php if ($idSolicitud > 0) { ?>
    <fieldset>
        <legend>1. Seleccionar Proveedor</legend>
        <div style="height: 200px; overflow-y: scroll;">
        <table style="font-size: 12px;">
            <tr>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px;"></th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Proveedor</th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Repuesto</th>
                <th title="O => ORIGINAL&#13;A => ALTERNATIVO" style="text-align: left; color: #0063DC; border: 1px solid #000000; font-weight: bold; padding-left: 5px; padding-right: 5px;">O/A</th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Cantidad</th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Monto Cot.</th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Disponibilidad</th>
                <th style="text-align: left; color: #0063DC; font-weight: bold; padding-left: 5px; padding-right: 5px; border: 1px solid #000000;">Estado</th>
            </tr>
            <?php
                if (count($lstRepuestoXProveedor)) {
                    $item = 0;
                    $idProveedor = '';
                    foreach ($lstRepuestoXProveedor as $dataRepuestoXProveedor) {
                        $disponibilidad = $dataRepuestoXProveedor->disponibilidad;
                        if ($disponibilidad != '') {
                            if ($disponibilidad == '0') {
                                $disponibilidad = STR_STOCK;
                            } else {
                                if ($disponibilidad == '1') {
                                    $disponibilidad .= STR_TXT_DIA;
                                } else {
                                    $disponibilidad .= STR_TXT_DIAS;
                                }
                            }
                        } else {
                            $disponibilidad = '-';
                        }
                        $tipo = $dataRepuestoXProveedor->tipo;
                        if ($tipo == 'O') {
                            $tipo = $tituloO;
                        } else {
                            $tipo = $tituloA;
                        }
            ?>
            <?php
                        if ($idProveedor != $dataRepuestoXProveedor->idProveedor) {
            ?>
            <tr>
                <td style="text-align: left;"><input type="checkbox" id="" name=""/></td>
                <td style="text-align: left; border: 1px solid #000000;"><?= $dataRepuestoXProveedor->razon ?></td>
                <td colspan="6" style="text-align: right; border: 1px solid #000000;"></td>
                <td>
                    <div id="star-rating<?= $item++ ?>">
                        <input type="radio" name="example" class="rating" value="1" data-readonly="true"/>
                        <input type="radio" name="example" class="rating" value="2" data-readonly="true"/>
                        <input type="radio" name="example" class="rating" value="3" data-readonly="true"/>
                        <input type="radio" name="example" class="rating" value="4" data-readonly="true"/>
                        <input type="radio" name="example" class="rating" value="5" data-readonly="true"/>
                    </div>
                </td>
            </tr>
            <?php
                        }
            ?>
            <tr>
                <td></td>
                <td style="text-align: left; border: 1px solid #000000;"></td>                
                <td style="text-align: left; border: 1px solid #000000;"><?= $dataRepuestoXProveedor->nomRepuesto ?></td>
                <td style="text-align: left; border: 1px solid #000000;"><?= $tipo ?></td>
                <td style="text-align: center; border: 1px solid #000000;"><?= $dataRepuestoXProveedor->cantidad ?></td>
                <td style="text-align: center; border: 1px solid #000000;"><?= $dataRepuestoXProveedor->monto ?></td>
                <td style="text-align: left; border: 1px solid #000000;"><?= $disponibilidad ?></td>
                <td style="text-align: left; border: 1px solid #000000;"><?= $dataRepuestoXProveedor->nomEstado ?></td>
                <td></td>
            </tr>
            <?php
                        $idProveedor = $dataRepuestoXProveedor->idProveedor;
                    }
                }
            ?>
        </table>
        </div>
    </fieldset>
    <fieldset>
        <legend>2. Seleccionar valoración</legend>
        <table style="width: 100%; font-size: 12px;">
            <tr>
                <td style="width: 60%; padding-left: 180px; vertical-align: middle;">
                    <div id="star-rating-calificar">
                        <input type="radio" name="example" class="rating" value="1" />
                        <input type="radio" name="example" class="rating" value="2" />
                        <input type="radio" name="example" class="rating" value="3"/>
                        <input type="radio" name="example" class="rating" value="4" />
                        <input type="radio" name="example" class="rating" value="5" />
                    </div>
                </td>
                <td style="width: 40%">
                    <table style="border: 1px solid #000000; width: 50%;">
                        <tr>
                            <th style="border-bottom: 1px solid #000000; border-right: 1px solid #000000; font-weight: bold; color: #0063DC;">Nro. Estrellas</th>
                            <th style="border-bottom: 1px solid #000000; font-weight: bold; color: #0063DC;">Descripción</th>
                        </tr>
                        <tr>
                            <td style="text-align: center; border-bottom: 1px solid #000000; border-right: 1px solid #000000; font-weight: bold;">1</td>
                            <td style="border-bottom: 1px solid #000000; font-weight: bold;">Muy malo</td>
                        </tr>
                        <tr>
                            <td style="text-align: center; border-bottom: 1px solid #000000; border-right: 1px solid #000000; font-weight: bold;">2</td>
                            <td style="border-bottom: 1px solid #000000; font-weight: bold;">Malo</td>
                        </tr>
                        <tr>
                            <td style="text-align: center; border-bottom: 1px solid #000000; border-right: 1px solid #000000; font-weight: bold;">3</td>
                            <td style="border-bottom: 1px solid #000000; font-weight: bold;">Regular</td>
                        </tr>
                        <tr>
                            <td style="text-align: center; border-bottom: 1px solid #000000; border-right: 1px solid #000000; font-weight: bold;">4</td>
                            <td style="border-bottom: 1px solid #000000; font-weight: bold;">Bueno</td>
                        </tr>
                        <tr>
                            <td style="text-align: center; border-right: 1px solid #000000; font-weight: bold;">5</td>
                            <td style="border-bottom: 1px solid #000000; font-weight: bold;">Muy bueno</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="2">Puede ingresar algún comentario (opcional): <input type="text" id="comentario" name="comentario" value=""/></td>
            </tr>
        </table>
    </fieldset>
    <?php } ?>
    <table style="width: 50%; margin-left: 400px;">
        <tr>
            <td colspan="2">
                <input type="button" value="Guardar" id="btnGuardar" name="btnGuardar" <?= $valorBoton ?>/>
                <script type="text/javascript">
                    $("#btnGuardar").click(function() {
                        if (confirm('¿Está seguro que desea Guardar los cambios?')) {
                            $("#solicitud").submit();
                        }
                    });
                </script>                
                <input type="button" value="Cerrar" id="btnCerrar" name="btnCerrar"/>
                <script type="text/javascript">
                    $("#btnCerrar").click(function() {
                        if (confirm('¿Está seguro que desea Cancelar los cambios?')) {
                            window.location = "<? echo base_url();?>index.php/solicitud";
                        }
                    });
                </script>
                <input type="hidden" id="numProveedores" name="numProveedores" value="<?= $numProveedores ?>"/>
            </td>
        </tr>
    </table>    
</form>
</div>
<?php $this->load->view('footer'); ?>